{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0e8081b0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'province': '四川省', 'city': '阿坝藏族羌族自治州', 'adcode': '513200', 'weather': '多云', 'temperature': 17, 'wind_direction': '西南风', 'wind_power': '2', 'humidity': 34, 'report_time': '2025-10-28 14:40:00'}\n",
      "多云\n"
     ]
    }
   ],
   "source": [
    "#接口调用\n",
    "#获取天气数据\n",
    "\n",
    "import requests\n",
    "\n",
    "base_url=\"https://uapis.cn/api/v1/misc/weather\"\n",
    "\n",
    "url=base_url+\"?city=阿坝&adcode=514200\"\n",
    "\n",
    "resp=requests.get(\n",
    "    url=url,\n",
    ")\n",
    "\n",
    "print(resp.json())\n",
    "print(resp.json()[\"weather\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6df3628c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'province': '四川', 'city': '阿坝', 'sp': '联通'}\n",
      "四川\n"
     ]
    }
   ],
   "source": [
    "#接口调用\n",
    "#查询手机号码归属地信息\n",
    "import requests\n",
    "\n",
    "base_url=\"https://uapis.cn/api/v1/misc/phoneinfo\"\n",
    "\n",
    "url=base_url+\"?phone=15583091286\"\n",
    "\n",
    "resp=requests.get(\n",
    "    url=url,\n",
    ")\n",
    "\n",
    "print(resp.json())\n",
    "print(resp.json()[\"province\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ddd329e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1. 为什么数学家永远不会感冒？\n",
      "因为他们已经把所有“病毒”都“隔离”在外了！（数学里的“隔离”指解方程时的步骤）\n",
      "\n",
      "2. 有一天键盘对鼠标说：“咱俩分手吧。”\n",
      "鼠标问：“为啥？”\n",
      "键盘说：“因为你老是在我上面点来点去，而我只能被你按在下面！”"
     ]
    }
   ],
   "source": [
    "#调用大模型\n",
    "from openai import OpenAI\n",
    "\n",
    "client=OpenAI(api_key=\"sk-zxcufrguvwrwydsczynkddqfdyobssuwvdcmjjldxfcgikvk\",base_url=\"https://api.siliconflow.cn/v1\")\n",
    "\n",
    "question=input(\"请输入您的问题：\")\n",
    "\n",
    "response=client.chat.completions.create(\n",
    "    model=\"deepseek-ai/DeepSeek-V3\",\n",
    "    messages=[\n",
    "        {\"role\":\"system\",\"content\":\"你是一位幽默大师\"},\n",
    "        {\"role\":\"user\",\"content\":question}\n",
    "    ],\n",
    "    temperature=0.7,\n",
    "    max_tokens=1024,\n",
    "    stream=True\n",
    ")\n",
    "#逐步接收并处理响应\n",
    "for chunk in response:\n",
    "    if not chunk.choices:\n",
    "        continue\n",
    "    if chunk.choices[0].delta.content:\n",
    "        print(chunk.choices[0].delta.content,end=\"\",flush=True)\n",
    "    if chunk.choices[0].delta.reasoning_content:\n",
    "        print(chunk.choices[0].delta.reasoning_content,end=\"\",flush=True)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Project",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
